
//
//  CarPictureSubmitVC.m
//  New_Runway
//
//  Created by mack on 2018/1/31.
//  Copyright © 2018年 NelsonJ. All rights reserved.
//

#import "CarPictureSubmitVC.h"
#import "CarPictureVC.h"
#import "CertificatesVC.h"
#import "IamgeFactory.h"
#import "CarAllImageModel.h"

@interface CarPictureSubmitVC ()
@property(nonatomic, strong) CarPictureVC *carPicVC;
@property(nonatomic, strong) CertificatesVC *certifiVC;
@property (nonatomic, strong) NSArray *titles;
@property(strong, nonatomic)NSArray *childVcs;
@property (weak, nonatomic) ZJScrollSegmentView *segmentView;
@property (weak, nonatomic) ZJContentView *contentView;
@property (nonatomic, strong) CarAllImageModel *imageModel;

@end

@implementation CarPictureSubmitVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationBarView.titleLabel.text = @"图片上传";
    self.view.backgroundColor = UIColorHex(0xf5f5f5);
    [self.navigationBarView.rightItem setTitle:@"确定" forState:UIControlStateNormal];
    [self setImageKeyWithValue];
    [self creatTopView];
    self.childVcs = [self setupChildVc];
    [self setupContentView];
    
}

-(void)setImageKeyWithValue{
    self.imageModel = [[CarAllImageModel alloc] init];
    self.imageModel.left_anterior = [IamgeFactory sharedMemory].left_anterior ? [IamgeFactory sharedMemory].left_anterior : @"";
    self.imageModel.vin = [IamgeFactory sharedMemory].vin ? [IamgeFactory sharedMemory].vin : @"";
    self.imageModel.right_rear = [IamgeFactory sharedMemory].right_rear ? [IamgeFactory sharedMemory].right_rear : @"";
    self.imageModel.driving_seat = [IamgeFactory sharedMemory].driving_seat ? [IamgeFactory sharedMemory].driving_seat : @"";
    self.imageModel.control_booth = [IamgeFactory sharedMemory].control_booth ? [IamgeFactory sharedMemory].control_booth : @"";
    self.imageModel.odograph = [IamgeFactory sharedMemory].odograph ? [IamgeFactory sharedMemory].odograph : @"";
    self.imageModel.open_trunk = [IamgeFactory sharedMemory].open_trunk ? [IamgeFactory sharedMemory].open_trunk : @"";
    self.imageModel.engine_bay = [IamgeFactory sharedMemory].engine_bay ? [IamgeFactory sharedMemory].engine_bay : @"";
    self.imageModel.gear_lever = [IamgeFactory sharedMemory].gear_lever ? [IamgeFactory sharedMemory].gear_lever : @"";
    self.imageModel.tyre = [IamgeFactory sharedMemory].tyre ? [IamgeFactory sharedMemory].tyre : @"";
    self.imageModel.insurance = [IamgeFactory sharedMemory].insurance ? [IamgeFactory sharedMemory].insurance : @"";
    self.imageModel.registration_license = [IamgeFactory sharedMemory].registration_license ? [IamgeFactory sharedMemory].registration_license : @"";
    self.imageModel.vehicle_license = [IamgeFactory sharedMemory].vehicle_license ? [IamgeFactory sharedMemory].vehicle_license : @"";

}
-(void)creatTopView{
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    kSelfWeak;
    ZJSegmentStyle *style = [[ZJSegmentStyle alloc] init];
    //显示遮盖
    style.showCover = NO;
    style.showLine = YES;
    style.scrollLineColor = MAIN_NAV_COLOR();
    style.titleFont = [UIFont systemFontOfSize:14];
    style.segmentViewBounces = NO;
    // 颜色渐变
    style.autoAdjustTitlesWidth =  YES;
    style.gradualChangeTitleColor = NO;
    style.normalTitleColor = MAIN_FONT_COLOR();
    style.selectedTitleColor = MAIN_NAV_COLOR();
    self.titles = @[@"车辆图片", @"证件图片"];
    style.titleMargin = 20;
    style.segmentHeight = 40;
    ZJScrollSegmentView *segment = [[ZJScrollSegmentView alloc] initWithFrame:CGRectMake(0, self.navH,Screen_width, 40) segmentStyle:style delegate:nil titles:self.titles titleDidClick:^(ZJTitleView *titleView, NSInteger index) {
        [weakSelf.contentView setContentOffSet:CGPointMake(weakSelf.contentView.bounds.size.width * index, 0.0) animated:YES];
        
    }];
    
    [self.view addSubview:segment];
    segment.backgroundColor = UIColorHex(0xf5f5f5);
    self.segmentView = segment;
    
    UILabel *remindLabel = [[UILabel alloc] init];
    remindLabel.textColor = MAIN_NAV_COLOR();
    remindLabel.font = [UIFont systemFontOfSize:15];
    remindLabel.textAlignment = NSTextAlignmentCenter;
    remindLabel.text = @"* 车辆拍照时建议横屏拍摄";
    remindLabel.frame = CGRectMake((Screen_width -200)/2 , self.view.bounds.size.height - self.BotH - 40, 200, 30);
    [self.view addSubview:remindLabel];
    
}

- (void)setupContentView {
    
    
    ZJContentView *content = [[ZJContentView alloc] initWithFrame:CGRectMake(0, self.navH + 40, self.view.bounds.size.width, self.view.bounds.size.height - self.navH  - self.BotH - 40 - 50) segmentView:self.segmentView parentViewController:self delegate:self];
    content.backgroundColor = [UIColor purpleColor];
    self.contentView = content;
    [self.view addSubview:self.contentView];
    
}
- (NSInteger)numberOfChildViewControllers {
    return self.titles.count;
}

- (UIViewController<ZJScrollPageViewChildVcDelegate> *)childViewController:(UIViewController<ZJScrollPageViewChildVcDelegate> *)reuseViewController forIndex:(NSInteger)index {
    
    
    if (!reuseViewController) {
        reuseViewController = self.childVcs[index];
    }
    
    return reuseViewController;
}
- (NSArray *)setupChildVc {
    
    
    NSArray *childVcs = [NSArray arrayWithObjects:self.carBaseVC,self.carConfigureVC,nil];
    return childVcs;
}
-(CarPictureVC *)carBaseVC{
    
    if (!_carPicVC) {
        _carPicVC = [[CarPictureVC alloc] init];
        
    }
    _carPicVC.infomodel = self.infomodel;
    _carPicVC.carID = self.carID;
    _carPicVC.imageModel = self.imageModel;
    return _carPicVC;
}

-(CertificatesVC *)carConfigureVC{
    if (!_certifiVC) {
        _certifiVC = [[CertificatesVC alloc] init];
        
    }
    _certifiVC.infomodel = self.infomodel;
    _certifiVC.carID = self.carID;
    _certifiVC.imageModel = self.imageModel;
    return _certifiVC;
}
-(void)rightItemClick{
 
    [_carPicVC saveIamgeToFactory];
    
    
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
